﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Besture.Bll;
using Besture.Common;
using Besture.Common.Helper;
using Besture.Model;

namespace Besture.UI.Portal.UserCenter
{
    public partial class Login : System.Web.UI.Page
    {
        private UserBaseDac dac = null;
        private UserBaseModel model = null;
        /// <summary>
        /// 登录后跳转的页面
        /// </summary>
        public string RedirectUrl = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {

        }        

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Login_Click(object sender, EventArgs e)
        {  
            model = new UserBaseModel();
            dac = new UserBaseDac();
            string UserName = txtLoginname.Value;
            string Pwd = LoginPwd.Value;
            //帐号登录
            if (UserName != "" && Pwd != "")
            {
                model = dac.Login(UserName, StringHelper.GetMD5(Pwd));

                
            }
            //跳转
            if (model != null)
            {
                if (model.UserType == Constants.USER_TYPE_DISTRIBUTOR)
                {
                    if (model.CheckStatus != Constants.USER_CHECK_SUCCESS)
                    {
                        FunHelper.Alert(this.Page, "您的账户正在审核中,请稍后登陆");
                        return;
                    }
                } 
                Session[Constants.SESSION_WEB_USER_MODEL] = model;
                Response.Redirect(!string.IsNullOrEmpty(RedirectUrl) ? RedirectUrl : "/Portal/Home/Index.aspx");
            }
            else
            {
                FunHelper.Alert(this.Page, "密码与用户名不匹配，请重新输入");
            }

        }
    }
}